const Mock = require('mockjs')

const List = []
const count = 100
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    title: '@csentence(5, 10)',
    cover: '@image("150x100")',
    try: '@cparagraph',
    conent: '@cparagraph',
    'sub_count|1': [5, 10, 15, 20],
    'price|1': [5, 10, 15, 20],
    'status|1': [0, 1],
    created_time: '@now',
    updated_time: '@now'

  }))
}

module.exports = [{
    url: '/vue-element-admin/video/list',
    type: 'get',
    response: config => {
      const {
        // eslint-disable-next-line no-unused-vars
        status,
        title,
        page = 1,
        limit = 20,
        sort
      } = config.query
      let mockList = List.filter(item => {
        // if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/vue-element-admin/video/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/vue-element-admin/video/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
